package com.hanrui.android.fragment.message.myvote;

import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.activity.message.myvote.AlreadyVoteActivity;
import com.hanrui.android.adapter.MyVoteListAdapter;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.MyVoteListBean;
import com.hanrui.android.net.contract.message.myvote.MyVoteListContract;
import com.hanrui.android.net.presenter.message.myvote.MyVoteListPresenter;
import com.hanrui.android.widget.SearchEditText;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * 已表决列表
 *
 */

public class AlreadyVoteListFragment extends BaseFragment<MyVoteListPresenter> implements MyVoteListContract.View{

    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;
    @BindView(R.id.recyclerview_swipeLayout)
    SwipeRefreshLayout swipeLayout;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @Inject
    MyVoteListAdapter adapter;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_audit;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {
        init();
    }


    public void init() {

        searchEditText.setEnabled(false);

        swipeLayout.setColorSchemeColors(ContextCompat.getColor(getActivity(),R.color.c_2795ff));
        swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                mPresenter.refresh(getActivity(),"2");

                }

        });

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setEnableLoadMore(false);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                MyVoteListBean bean = (MyVoteListBean) adapter.getItem(position);
                AlreadyVoteActivity.start(getActivity(),bean.getId());
            }
        });


    }

    @Override
    public void onResume() {
        super.onResume();
        swipeLayout.setRefreshing(true);
        mPresenter.refresh(getActivity(),"2");
    }

    public static AlreadyVoteListFragment newInstance() {return new AlreadyVoteListFragment();}

    @Override
    public void notYetList(List<MyVoteListBean> dataList, int loadType) {

    }

    @Override
    public void alreadyList(List<MyVoteListBean> dataList, int loadType) {

        setLoadDataResult(swipeLayout, adapter, dataList, loadType, false);

    }
}
